import { createRouter, createWebHistory } from "vue-router";
import Dept from "@/views/Dept/index.vue";
import Login from "@/views/Login.vue";
import { RouteRecordRaw } from "vue-router";
const RouterModuleList: RouteRecordRaw[] = []
const modules: any = import.meta.glob("./modules/**/*.ts", { eager: true });
Object.keys(modules).forEach((key) => {
  const mod = modules[key].default || {};
  const modlist = Array.isArray(mod) ? [...mod] : [mod];
  RouterModuleList.push(...modlist);
});
const routes = [
  {
    path: "/",
    name: "login",
    component: Login,
    meta: {
      title: "登录",
    },
  },
  {
    path: "/MeetingRoomManagement",
    component: Dept,
    redirect: "/MeetingRoomManagement/list",
    meta: {
      title: "首页",
    },
  },
];

const baseRoutes:any = [...routes, ...RouterModuleList];
const router:any = createRouter({
  // 4. 内部提供了 history 模式的实现。为了简单起见，我们在这里使用 hash 模式。
  history: createWebHistory(),
  routes: baseRoutes, // `routes: routes` 的缩写
});

// router.beforeEach((to, from, next) => {
// console.log(to);
// console.log(from);
// document.title = (to?.meta?.title as string) || document.title;
// if (to.path != "/login") {
// console.log(localStorage.getItem('token'))
//判断是否登陆
// if (!localStorage.getItem("token")) {
// next({
//   path: "/login",
//   query: {
//     redirect: to.fullPath,
//   },
// });
// }
// }
// next();
// });
export default router;
export { RouterModuleList };
